/**
 * Created by Administrator on 2018/7/30 0030.
 */

$(window).ready(function(){
    var textHeight = $(".cpfl-text1").offset().top;
    //var scrollTop = $(".cpfl-text").scrollTop();
    var arr = [1,2,3,4,5]
    var Array = [];
    console.log($(".dc-text:nth-child(1)").offset().top)
    for(var i=1;i<7;i++){
        Array.push($(".dc-text:nth-child("+i+")").offset().top);
    }
    console.log(Array)
    $(".cpfl-text").scroll(function(){
        var scrollTop = $(".cpfl-text").scrollTop()+textHeight;
        //console.log(scrollTop)
        //console.log(textHeight)
        arr.forEach(function(item,index){
            if(((scrollTop)>=Array[index])&&(scrollTop<Array[(index+1)])){
                console.log(scrollTop);
                console.log(index)
                $(".circle").removeClass("active");
                $(".dc-nav-list").removeClass("active");
                $(".circle:nth-child("+item+")").addClass("active")
                $(".dc-nav-list:nth-child("+item+")").addClass("active")
            }
        });
    });
    $(".dc-nav-list").click(function(){
        var indexNum = $(this).index();
        var scrollHeight = Array[indexNum]
        $(".cpfl-text").scrollTop(scrollHeight-textHeight)
    })
});